import 'package:flutter/material.dart';
import 'package:fun_shop/src/ui/pages/cart/cart_page.dart';
import 'package:fun_shop/src/ui/pages/fav/fav_page.dart';
import 'package:fun_shop/src/ui/pages/home/home_page.dart';
import 'package:fun_shop/src/ui/pages/mine/mine_page.dart';

class IndexPage extends StatefulWidget {
  const IndexPage({super.key});

  @override
  State<IndexPage> createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: Theme.of(context).primaryColor,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home_outlined), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.shopping_cart_outlined), label: '购物车'),
          BottomNavigationBarItem(icon: Icon(Icons.favorite_border), label: '收藏'),
          BottomNavigationBarItem(icon: Icon(Icons.person_outline), label: '我的'),
        ],
      ),

      body: IndexedStack(
        index: _currentIndex,
        children: const [
          HomePage(),
          CartPage(),
          FavPage(),
          MinePage()
        ],
      ),
    );
  }
}